package adc.budget.impl.hb.bo;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import adc.budget.spec.bo.ISource;

@Entity
@Table(name="SOURCE")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING)
public class HbSource extends HbBudgetBo implements ISource {

    private static final long serialVersionUID = 1L;

    private String name;
    private String notes;

    @Override
    @Column(length=128)
    public String getName() {
        return name;
    }

    @Override
    @Column(unique=true)
    public void setName(String name) {
        this.name = name;
    }

    @Override
    @Column(length=256)
    public String getNotes() {
        return notes;
    }

    @Override
    public void setNotes(String notes) {
        this.notes = notes;
    }

    @Override
    public boolean equals(final Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof HbSource)) {
            return false;
        }

        return equals(this.getId(), ((HbSource) other).getId())
                && equals(this.getName(), ((HbSource) other).getName());
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(getId()).append(getName()).toHashCode();
    }

    @Override
    protected void appendPropsToString(final ToStringBuilder builder) {
        super.appendPropsToString(builder);
        builder.append("name", name);
    }

    @Override
    public int compareTo(final ISource other) {
        return name.compareTo(other.getName());
    }
}
